/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bd.util;

/**
 *
 * http://ru.wikipedia.org/wiki/PJW-32
 * http://vak.ru/doku.php/proj/hash/sources
 *
 * @author niyaz
 */
public class Hash {

    public static long getStartHash() {
        return 0x00000000;
    }

    ;

    public static long getStopHash() {
        long f = 0x0fffffff;
        //f <<= 4;
        // f += 15;
        return f;
    }

    ;

    // unsigned int PJWHash (char *str, unsigned int len)
    public static long getHash(String str) {

        long len = str.length();
        long hash = 0;
        long test = 0;
        long i = 0;
        int j = 0;

        for (i = 0; i < len; j++, i++) {
            hash = (hash << 4) + (char) (str.charAt(j));
            if ((test = hash & 0xf0000000) != 0) {
                hash = ((hash ^ (test >> 24)) & (0xfffffff));
            }
        }
        return hash;
    }
}
